<template>
    <van-index-bar>
  
      <template v-for="item in addressList" :key="item.letter">
        <van-index-anchor :index="item.letter.toUpperCase()" />
        <van-cell
          v-for="city in item.data"
          :key="city.cityId"
          :title="city.name"
  
          @click="goHome(city.name)"
        /> 
        
      </template>
  
    </van-index-bar>
  
  </template>
  
  <script>
  import axios from "axios";
  
  export default {
    name: "Address",
    data() {
      return {
        addressList: [],
      };
    },
    created() {
      this.getAddress();
    },
    methods: {
      getAddress() {
        axios.get("/api2308/city/sortCity.json").then((res) => {
          this.addressList = res.data;
        });
      },
      goHome(cityName){
          localStorage.setItem("cityName",cityName);
          this.$router.push("/Home");
      }
    },
  };
  </script>
  
  <style>
  </style>